﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Windows.Threading;

namespace Asteroids.Game.View
{
    /// <summary>
    /// Interaction logic for GameScreen.xaml
    /// </summary>
    public partial class GameScreen : UserControl, INotifyPropertyChanged
    {
        public GameScreen()
        {
            _renderStuffs = new Canvas();
            InitializeComponent();
            RenderPane.Content = RenderStuffs;

            MainWindow.KeyDownEvent += KeyDown;
        }

        private Canvas _renderStuffs;
        public Canvas RenderStuffs
        {
            get { return _renderStuffs; }
        }

        public void Render(object sender, EventArgs e)
        {

            _renderStuffs.Children.Clear();
            foreach (IRender renderable in Game.Instance.GetAllRenderables())
            {
                RenderStuffs.Children.Add(renderable.Render(new RenderEventArgs()));
            }
            if (PropertyChanged != null)
                PropertyChanged(this, new PropertyChangedEventArgs("RenderStuffs"));
        }

        private new static void KeyDown(object sender, KeyEventArgs e)
        {
            if (e.Key == Key.P)
            {
                Game.Instance.IsPaused = true;
                MainWindow.Timer.Stop();
                MainWindow.Instance.PauseMenuUC.Visibility = Visibility.Visible;
            }
        }
        public event PropertyChangedEventHandler PropertyChanged;
    }
}
